package cc.realxyq.springboot.db.redis;

import cc.realxyq.springboot.db.utils.JsonResult;
import cc.realxyq.springboot.db.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author : [buleing]
 * @version : [v1.0]
 * @description : [一句话描述该类的功能]
 * @createTime : [2021/6/11 15:36]
 * @updateUser : [buleing]
 * @updateTime : [2021/6/11 15:36]
 * @updateRemark : [说明本次修改内容]
 */
@RestController
public class JedisController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/redis/delete/{key}")
    public JsonResult delete(@PathVariable("key") String key){
        return redisTemplate.delete(key)?new JsonResult(ResultCode.SUCCESS)
                :new JsonResult(ResultCode.SUCCESS_FAIL);
    }

    @GetMapping("/redis/has/{key}")
    public JsonResult hasKey(@PathVariable("key") String key){
        return redisTemplate.hasKey(key)?new JsonResult(ResultCode.SUCCESS)
                :new JsonResult(ResultCode.SUCCESS_FAIL);
    }

    @PostMapping("/redis/create")
    public JsonResult set(String key,String value){
        redisTemplate.opsForValue().set(key, value);
        return new JsonResult(ResultCode.SUCCESS);
    }

}
